﻿<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools Documentation - Request/Request.JSON</title>
</head>

<body>
  <div id="docs" class="doc">
    <div class="methods">
      <h4 class="menu-item"><a href="#Request-JSON">Request.JSON</a></h4>
    </div>
    <div class="l-border r-border span-15 content">
				<h1 id="Request-JSON"><a href="#Request-JSON">Class: Request.JSON</a></h1>

<p class="description">Wrapped Request with automated receiving of JavaScript Objects in JSON Format.</p>

<h3>Extends:</h3>

<p><a href="Request.html">Request</a></p>

<h3>Syntax:</h3>

<pre class="javascript"><span class="kw2">var</span> myJSONRemote = <span class="kw2">new</span> Request.<span class="me1">JSON</span><span class="br0">(</span><span class="br0">[</span>options<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments:</h3>

<ol>
<li>options - (<em>object</em>, optional) See below.</li>
</ol>
<h3>Options:</h3>

<ul>
<li>secure  - (<em>boolean</em>: defaults to true) If set to true, a syntax check will be done on the result JSON (see <a href="../Utilities/JSON.html#JSON:decode">JSON.decode</a>).</li>
</ul>
<h3>Events:</h3>

<h4>success</h4>

<p>Fired when the request completes. This overrides the signature of the Request success event.</p>

<h5>Signature:</h5>

<pre class="javascript">onSuccess<span class="br0">(</span>responseJSON, responseText<span class="br0">)</span>
</pre>

<h5>Arguments:</h5>

<ol>
<li>responseJSON - (<em>object</em>) The JSON response object from the remote request.</li>
<li>responseText - (<em>string</em>) The JSON response as string.</li>
</ol>
<h4>error</h4>

<p>Fired when the parsed JSON is not valid and the secure option is set.</p>

<h5>Signature:</h5>

<pre class="javascript"><span class="kw3">onError</span><span class="br0">(</span>text, error<span class="br0">)</span>
</pre>

<h5>Arguments:</h5>

<ol>
<li>text - (string) The response text.</li>
<li>error - (string) The error message.</li>
</ol>
<h3>Returns:</h3>

<ul>
<li>(<em>object</em>) A new Request.JSON instance.</li>
</ul>
<h3>Example:</h3>

<pre class="javascript"><span class="co1">// this code will send a data object via a GET request and alert the retrieved data.</span>
<span class="kw2">var</span> jsonRequest = <span class="kw2">new</span> Request.<span class="me1">JSON</span><span class="br0">(</span><span class="br0">{</span>url: <span class="st0">'http://site.com/tellMeAge.php'</span>, onSuccess: <span class="kw2">function</span><span class="br0">(</span>person<span class="br0">)</span><span class="br0">{</span>
    <span class="kw3">alert</span><span class="br0">(</span>person.<span class="me1">age</span><span class="br0">)</span>;    <span class="co1">// alerts "25 years".</span>
    <span class="kw3">alert</span><span class="br0">(</span>person.<span class="me1">height</span><span class="br0">)</span>; <span class="co1">// alerts "170 cm".</span>
    <span class="kw3">alert</span><span class="br0">(</span>person.<span class="me1">weight</span><span class="br0">)</span>; <span class="co1">// alerts "120 kg".</span>
<span class="br0">}</span><span class="br0">}</span><span class="br0">)</span>.<span class="me1">get</span><span class="br0">(</span><span class="br0">{</span><span class="st0">'firstName'</span>: <span class="st0">'John'</span>, <span class="st0">'lastName'</span>: <span class="st0">'Doe'</span><span class="br0">}</span><span class="br0">)</span>;
</pre>

    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
